<?php


/** ensure this file is being included by a parent file */
defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );

/**
 * @package	
 */
class HelpDeskHelperPlugin {

	/**
	 * Returns a reference to the global Event Dispatcher object, only creating it
	 * if it doesn't already exist.
	 * @param mixed Boolean
	 * @param mixed Boolean
	 * @return array
	 */
	function &getInstance() {
		
		static $instance;
		
		if (!is_object($instance)) {
			if (HelpDeskHelperUtility::class_exists( 'JDispatcher' )) {
				$instance = new JDispatcher();
			} elseif (HelpDeskHelperUtility::class_exists( 'mosMambotHandler' )) {
				global $_MAMBOTS;
				$instance = $_MAMBOTS;
			} 
		}
		
		return $instance;
	}	

	/**
	 * 
	 * @param $group
	 * @param $element
	 * @param $autocreate
	 * @param $dispatcher
	 * @param $published
	 * @param $params
	 * @return unknown_type
	 */
	function importPlugin( $group, $element, $autocreate=true, $dispatcher=null, $published='1', $params='' )
	{
		$return = false;
		
		if (HelpDeskHelperUtility::class_exists( 'JPluginHelper' )) 
		{
			$return = JPluginHelper::importPlugin( $group, $element, $autocreate, $dispatcher );		
		} elseif (HelpDeskHelperUtility::class_exists( 'mosMambotHandler' )) 
		{
			global $_MAMBOTS;
			$return = $_MAMBOTS->loadBot( $group, $element, $published, $params );
		}
		
		return $return;
	}
	
	/**
	 * Loads all the plugin files of a particular group
	 * @param mixed Boolean
	 * @param mixed Boolean
	 * @return array
	 */
	function &importPluginGroup( $group ) 
	{
		$return = false;
		
		if (HelpDeskHelperUtility::class_exists( 'JPluginHelper' )) {
			$return = JPluginHelper::importPlugin( $group );		
		} elseif (HelpDeskHelperUtility::class_exists( 'mosMambotHandler' )) {
			global $_MAMBOTS;
			$return = $_MAMBOTS->loadBotGroup( $group );
		}
		
		return $return;
	}	
}